/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package scrolltextencoder;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 *
 * @author bitvision
 */
public class ScrollTextEncoder {

   
    public static int BASE = 128;
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        if (args.length!=2) {
            System.out.println("ScrollTextEncoder <input text file> <output enconded file>");
            System.exit(1);
        }
        
        String text = readFile(args[0]);
        //FileOutputStream outputFile = new FileOutputStream(new File(args[2]));        
        PrintWriter out = new PrintWriter(args[1]);
        
        //System.out.println(">>>>>>>>>>>>>" + text +"<<<<<<<<<<<<<<");
        char[] characters = text.toCharArray();

        String lineEven = "db   ";
        String lineOdd =  "db   ";
        
        int cn = 0;
       
        for (int i = 0 ; i< characters.length ; i++){
                        
            if ((characters[i]>='A' && characters[i]<='Z')|| characters[i]==' ' || characters[i]=='.' || characters[i]==',') {
               //System.out.println("*"+characters[i] + "    "+ Integer.toHexString(characters[i]));

                int cbase = 128 + (characters[i]-'A' )*2;
                if (characters[i]==',')
                    cbase = 180;
                if (characters[i]=='.')
                    cbase = 182;
                
                lineEven = lineEven + "0x"+String.format("%02X",cbase & 0xFF);//"0x"+ Integer.toHexString(cbase);
                lineOdd = lineOdd + "0x"+String.format("%02X",(cbase+1) & 0xFF);
                
                cn++;
                
                if (cn % 32 == 0) {
                    out.println(lineEven);
                    out.println(lineOdd);
                    lineEven = "db   ";
                    lineOdd =  "db   ";
                } else {
                    lineEven = lineEven + ",";
                    lineOdd = lineOdd + ",";
                }
                
           }
            
        }
        
        if (lineEven.length()>"db   ".length()){
            out.println(lineEven);
            out.println(lineOdd);
        }
        
        out.close();
        
    }
 
    
    
    static String readFile(String path) throws IOException 
    {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, StandardCharsets.UTF_8);
    }
    
}
